package com.yq233.controller;

import com.yq233.service.UserService;
import com.yq233.utills.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(value = "/adduser", method = RequestMethod.POST)
    public String adduser(@RequestParam("id") int id,
                          @RequestParam("username") String username,
                          @RequestParam("password") String password) {
        userService.addUsear(id, username, password);
        return Result.okGetString("添加成功");
    }

    @RequestMapping(value = "/deluser", method = RequestMethod.DELETE)
    public String deluser(@RequestParam("id") int id) {
        userService.delUser(id);
        return Result.okGetString("删除成功");
    }

    @RequestMapping(value = "/findUserName")
    public String findUserName(@RequestParam("username") String username) {
        Object list = userService.findUserName(username);
        return Result.okGetStringBydata("查找成功", list);
    }

    @RequestMapping(value = "/updataname", method = RequestMethod.PUT)
    public String updataname(@RequestParam("id") int id) {
        userService.updataName(id);
        return Result.okGetString("更新成功");
    }
}
